package com.yanqu.road.server.cmd.activity.huashigang;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.huashigang.HuaShiGangFloorCellData;
import com.yanqu.road.entity.activity.huashigang.HuaShiGangUserFloor;
import com.yanqu.road.pb.huashigang.HuaShiGangProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.huashigang.HuaShiGangModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.huashigang.HuaShiGangMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @Author wpj
 * @Date 2020/10/11
 */
@Cmd(code = GameProtocol.S_HUA_SHI_GANG_FLOOR_DATA, desc = "花石纲宝库数据")
public class GetHuaShiGangFloorDataCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
//        ret = HuaShiGangMgr.getActivityInfoRet(player);
//        if (ret != 0) {
//            return;
//        }
        ActivityInfo activityInfo = HuaShiGangMgr.getActivityInfo();
        if (!ActivityMgr.activityInShowTime(activityInfo)) {
            ret = GameErrorCode.E_HUA_SHI_GAG_NOT_IN_FIGHT_TIME;
            return;
        }

        HuaShiGangUserFloor huaShiGangUserFloor = player.getModule(HuaShiGangModule.class).getFloorData(activityInfo.getActivityId());
        HuaShiGangProto.HuaShiGangFloorRespMsg.Builder builder = HuaShiGangProto.HuaShiGangFloorRespMsg.newBuilder();
        builder.setRet(ret);
        builder.setFloor(huaShiGangUserFloor.getFloor());
        for (HuaShiGangFloorCellData cellData : huaShiGangUserFloor.getCellDataList()) {
            HuaShiGangProto.HuaShiGangCellData.Builder cell = HuaShiGangProto.HuaShiGangCellData.newBuilder();
            cell.setOpen(cellData.isOpen());
            if (cellData.isOpen()) {
                cell.setReward(cellData.getReward());
            } else {
                cell.setReward("");
            }
            builder.addCell(cell);
        }
        builder.setGotBigReward(huaShiGangUserFloor.getGotBigReward());
        player.sendPacket(ClientProtocol.U_HUA_SHI_GANG_FLOOR_DATA, builder);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            HuaShiGangProto.HuaShiGangFloorRespMsg.Builder builder = HuaShiGangProto.HuaShiGangFloorRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_HUA_SHI_GANG_FLOOR_DATA, builder);
        }
    }
}
